package com.openbravo.beans;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class JTimePanel extends JPanel
{
  public static final int BUTTONS_ALL = 3;
  public static final int BUTTONS_HOUR = 1;
  public static final int BUTTONS_MINUTE = 2;
  private DateFormat fmtTime = DateFormat.getTimeInstance(3);
  private JClockPanel m_jclock;
  private Date m_dMinDate;
  private Date m_dMaxDate;
  private JButtonDate m_jbtnplushour = null;
  private JButtonDate m_jbtnminushour = null;
  private JButtonDate m_jbtnplusfifteen = null;
  private JButtonDate m_jbtnminusfifteen = null;
  private JButtonDate m_jbtnplusminute = null;
  private JButtonDate m_jbtnminusminute = null;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel m_jactions;
  private JLabel m_jlblSeparator;
  private JLabel m_jlblTime;
  private JLabel m_jlblTime2;
  private JPanel m_jtime;

  public JTimePanel()
  {
    this(null, 3);
  }

  public JTimePanel(Date paramDate)
  {
    this(paramDate, 3);
  }

  public JTimePanel(Date paramDate, int paramInt)
  {
    initComponents();
    this.m_jclock = new JClockPanel(false);
    this.jPanel2.add(this.m_jclock, "Center");
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("H:mm");
    DateClick localDateClick = new DateClick( );
    GregorianCalendar localGregorianCalendar;
    if ((paramInt & 0x1) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 1, 0);
      this.m_jbtnplushour = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1uparrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnplushour);
    }
    if ((paramInt & 0x2) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 0, 15);
      this.m_jbtnplusfifteen = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1uparrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnplusfifteen);
    }
    if ((paramInt & 0x2) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 0, 1);
      this.m_jbtnplusminute = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1uparrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnplusminute);
    }
    if ((paramInt & 0x2) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 0, 1);
      this.m_jbtnminusminute = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnminusminute);
    }
    if ((paramInt & 0x2) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 0, 15);
      this.m_jbtnminusfifteen = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnminusfifteen);
    }
    if ((paramInt & 0x1) > 0)
    {
      localGregorianCalendar = new GregorianCalendar(1900, 0, 0, 1, 0);
      this.m_jbtnminushour = new JButtonDate(localSimpleDateFormat.format(localGregorianCalendar.getTime()), new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow.png")), localDateClick);
      this.m_jactions.add(this.m_jbtnminushour);
    }
    this.m_dMinDate = null;
    this.m_dMaxDate = null;
    this.m_jclock.setTime(paramDate);
    renderTime();
  }

  public void setDateMidNight()
  {
    setDate(new GregorianCalendar(1900, 0, 0, 0, 0).getTime());
  }

  public void setDate(Date paramDate)
  {
    Date localDate = this.m_jclock.getTime();
    if (((paramDate == null) && (localDate != null)) || ((paramDate != null) && (!paramDate.equals(localDate)) && (checkDates(paramDate))))
    {
      this.m_jclock.setTime(paramDate);
      renderTime();
      firePropertyChange("Date", localDate, paramDate);
    }
  }

  private boolean checkDates(Date paramDate)
  {
    return (paramDate == null) || (((this.m_dMaxDate == null) || (this.m_dMaxDate.compareTo(paramDate) > 0)) && ((this.m_dMinDate == null) || (this.m_dMinDate.compareTo(paramDate) <= 0)));
  }

  public Date getDate()
  {
    return this.m_jclock.getTime();
  }

  public void setCheckDates(Date paramDate1, Date paramDate2)
  {
    this.m_dMinDate = paramDate1;
    this.m_dMaxDate = paramDate2;
    setDate(null);
    renderTime();
  }

  public void setEnabled(boolean paramBoolean)
  {
    super.setEnabled(paramBoolean);
    renderTime();
  }

  public void setPeriod(long paramLong)
  {
    this.m_jclock.setPeriod(paramLong);
    renderTime();
  }

  private void renderTime()
  {
    Date localDate = this.m_jclock.getTime();
    if (localDate == null)
    {
      if (this.m_jbtnplushour != null)
        this.m_jbtnplushour.setEnabled(false);
      if (this.m_jbtnminushour != null)
        this.m_jbtnminushour.setEnabled(false);
      if (this.m_jbtnplusfifteen != null)
        this.m_jbtnplusfifteen.setEnabled(false);
      if (this.m_jbtnminusfifteen != null)
        this.m_jbtnminusfifteen.setEnabled(false);
      if (this.m_jbtnplusminute != null)
        this.m_jbtnplusminute.setEnabled(false);
      if (this.m_jbtnminusminute != null)
        this.m_jbtnminusminute.setEnabled(false);
      this.m_jlblTime.setText("  ");
      this.m_jlblSeparator.setVisible(false);
      this.m_jlblTime2.setVisible(false);
      this.m_jtime.revalidate();
    }
    else
    {
      GregorianCalendar localGregorianCalendar = new GregorianCalendar();
      localGregorianCalendar.setTime(localDate);
      localGregorianCalendar.add(11, 1);
      if (this.m_jbtnplushour != null)
      {
        this.m_jbtnplushour.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnplushour.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      localGregorianCalendar.add(11, -2);
      if (this.m_jbtnminushour != null)
      {
        this.m_jbtnminushour.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnminushour.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      localGregorianCalendar.setTime(localDate);
      localGregorianCalendar.add(12, 15);
      if (this.m_jbtnplusfifteen != null)
      {
        this.m_jbtnplusfifteen.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnplusfifteen.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      localGregorianCalendar.add(12, -30);
      if (this.m_jbtnminusfifteen != null)
      {
        this.m_jbtnminusfifteen.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnminusfifteen.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      localGregorianCalendar.setTime(localDate);
      localGregorianCalendar.add(12, 1);
      if (this.m_jbtnplusminute != null)
      {
        this.m_jbtnplusminute.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnplusminute.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      localGregorianCalendar.add(12, -2);
      if (this.m_jbtnminusminute != null)
      {
        this.m_jbtnminusminute.DateInf = localGregorianCalendar.getTime();
        this.m_jbtnminusminute.setEnabled((isEnabled()) && (checkDates(localGregorianCalendar.getTime())));
      }
      if (this.m_jclock.getPeriod() > 0L)
      {
        this.m_jlblTime.setText(this.fmtTime.format(localDate));
        this.m_jlblTime2.setText(this.fmtTime.format(new Date(localDate.getTime() + this.m_jclock.getPeriod())));
        this.m_jlblSeparator.setVisible(true);
        this.m_jlblTime2.setVisible(true);
        this.m_jtime.revalidate();
      }
      else
      {
        this.m_jlblTime.setText(this.fmtTime.format(localDate));
        this.m_jlblSeparator.setVisible(false);
        this.m_jlblTime2.setVisible(false);
        this.m_jtime.revalidate();
      }
    }
    this.m_jclock.setEnabled(isEnabled());
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.m_jactions = new JPanel();
    this.jPanel2 = new JPanel();
    this.m_jtime = new JPanel();
    this.m_jlblTime = new JLabel();
    this.m_jlblSeparator = new JLabel();
    this.m_jlblTime2 = new JLabel();
    setLayout(new BorderLayout());
    this.jPanel1.setLayout(new BorderLayout());
    this.m_jactions.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    this.m_jactions.setLayout(new GridLayout(0, 1, 0, 5));
    this.jPanel1.add(this.m_jactions, "North");
    add(this.jPanel1, "After");
    this.jPanel2.setBorder(BorderFactory.createEtchedBorder());
    this.jPanel2.setLayout(new BorderLayout());
    this.m_jtime.add(this.m_jlblTime);
    this.m_jlblSeparator.setText(" - ");
    this.m_jtime.add(this.m_jlblSeparator);
    this.m_jtime.add(this.m_jlblTime2);
    this.jPanel2.add(this.m_jtime, "North");
    add(this.jPanel2, "Center");
  }

  private static class JButtonDate extends JButton
  {
    public Date DateInf;

    public JButtonDate(ActionListener paramActionListener)
    {
      initComponent();
      addActionListener(paramActionListener);
    }

    public JButtonDate(String paramString, ActionListener paramActionListener)
    {
      super();
      initComponent();
      addActionListener(paramActionListener);
    }

    public JButtonDate(String paramString, Icon paramIcon, ActionListener paramActionListener)
    {
      super(paramIcon);
      initComponent();
      addActionListener(paramActionListener);
    }

    private void initComponent()
    {
      this.DateInf = null;
      setRequestFocusEnabled(false);
      setFocusPainted(false);
      setFocusable(false);
    }
  }

  private class DateClick
    implements ActionListener
  {
    private DateClick()
    {
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      JTimePanel.JButtonDate localJButtonDate = (JTimePanel.JButtonDate)paramActionEvent.getSource();
      if (localJButtonDate.DateInf != null)
        JTimePanel.this.setDate(localJButtonDate.DateInf);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.beans.JTimePanel
 * JD-Core Version:    0.6.0
 */